public void createMatGraph(int n, int e, String[] vexs, String[] edgs) {
    this.n = n; // 设置顶点数
    this.e = e; // 设置边数
    for(int i = 0;i<n;i++)
    {
        this.vexs[i] = vexs[i];
    }

    for(int i = 0;i<e;i++)
    {
        int x = -1;
        int y=-1;
        String[] tmp = edgs[i].split(",");
        for(int j = 0;j<n;j++)
        {
            if(vexs[j].equals(tmp[0]))
                x = j;
            if(vexs[j].equals(tmp[1]))
                y = j;
        }
        if((x!=-1)&&(y!=-1))
        {
            this.edgs[x][y] = 1;
            this.edgs[y][x] = 1;
        }
    }
}


public int degree(int v)
{
    int count = 0;
    for(int i = 0;i<n;i++)
    {
        if(edgs[i][v]==1)
            count++;
    }
    for(int j = 0;j<n;j++)
    {
        if(edgs[v][j]==1)
            count++;
    }
    if(edgs[v][v]==1)
        count--;
    return count/2;
}





public String[] getW(int v)
{
    int count = 0;
    int arr[] = new int[this.n];
    for(int i = 0;i<n;i++)
    {
        if(edgs[i][v]==1)
        {
            arr[i] = 1;
            count++;
        }
    }
    for(int j = 0;j<n;j++)
    {
        if(edgs[v][j]==1)
        {
            arr[j] = 1;
            count++;
        }
    }
    if(edgs[v][v]==1)
        count--;
    count/=2;
    String[] res = new String[count];
    int pos = 0;
    for(int i = 0;i<n;i++)
    {
        if(arr[i]==1)
            res[pos++] = vexs[i];
    }
    return res;
}


void DFSMatGraph()
{
    boolean[] visited = new boolean[n];
    for(int i = 0;i<n;i++)
    {
        if(!visited[i])
        {
            DFS(i,visited);
        }
    }
}
void DFS(int v,boolean[] visited)
{
    visited[v]= true;
    System.out.print(vexs[v]+" ");
    for(int i = 0;i<n;i++)
    {
        if(edgs[v][i]==1&&!visited[i])
        {
            DFS(i,visited);
        }
    }
}




void BFSMatGraph()
{
    boolean[] visited = new boolean[n];
    for(int i = 0;i<n;i++)
    {
        if(!visited[i])
        {
            BFS(i,visited);
            System.out.println();
        }
    }
}
void BFS(int v,boolean[] visited)
{
    Queue<Integer> queue = new LinkedList<>();
    visited[v] = true;
    queue.add(v);

    while (!queue.isEmpty()) {
        int cur = queue.poll();
        System.out.print(vexs[cur] + " ");

        for (int i = 0; i < n; i++) {
            if (edgs[cur][i] == 1 && !visited[i]) {
                visited[i] = true;
                queue.add(i);
            }
        }
    }
}
